package com.vint.mi;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 1.done
 * 2.easy, 太过麻烦
 * 3. 三元组和为0的个数
 */
public class Mi15 {
    public static String solution(String line){
        String[] src = line.split(",");
        int[] a=new int[src.length];
        for(int i=0;i<src.length;i++)a[i] = Integer.parseInt(src[i]);
        Arrays.sort(a);
        System.out.println(String.valueOf(dup(a,0)));
	    return String.valueOf(sumSpecific(a,0));
    }

    //dup
	public static int dup(int[]a, int sum) {
		int count = 0;
		if (null == a) return count;
		int len = a.length;
		if (len < 3) return count;
		for (int i = 0; i < len - 2; i++) {
			if(i>0&&a[i]==a[i-1])continue;
			for (int j = len - 1; j > i + 1; j--) {
				if(j<len-1&&a[j]==a[j+1])continue;
				for (int k = i + 1; k < j; k++) {
					if(k>0&&a[k]==a[k-1])continue;
					if(k<len-1&&a[k]==a[j])continue;
					if(a[i] + a[j] + a[k] == sum){
						count++;
					}else if(a[i] + a[j] + a[k] > sum){
						break;
					}
				}
			}
		}
		return count;
	}
    //这里sum为0,重复的没有计算之内
    public static int sumSpecific(int[]a, int sum) {
	    Map<Integer,Integer>map = new HashMap<>();
	    int count = 0;
	    for(int i=0;i<a.length;i++){
	    	if(map.containsKey(a[i])){
	    		int value = map.get(a[i])+1;
	    		map.put(a[i],value);
		    }else{
			    map.put(a[i],1);
		    }
	    }
	    Iterable<Map.Entry<Integer,Integer>>iterable = map.entrySet();
	    for(Map.Entry<Integer,Integer>i:iterable){
	    	int key = i.getKey();
	    	int valeu = i.getValue();
	    	if(key!=0) {
			    if (valeu >= 2&&map.keySet().contains(sum-2*key)) count++;
		    }else{
	    	    if(valeu>=3)count++;
		    }
	    }
		return count;
    }
    public static void main(String[] args){
//        System.out.println(solution("-1,0,1,2,-1,-4"));
	    System.out.println(solution("-4,-2,-2,-2,0,1,2,2,2,3,3,4,4,6,6"));
    }
}
